﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ArtificialIntelligence.cs" company="melcoprog">
//   Copyright (c) melcoprog. All rights reserved.
// </copyright>
// <summary>
//   Defines the ArtificialIntelligence type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace CreatureSheep.AI
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;

    using Creature;

    /// <summary>
    /// The ai state machine.
    /// </summary>
    public class ArtificialIntelligence : IStateMachine
    {
        /// <summary>
        /// The artificial intelligence configuration.
        /// </summary>
        private readonly List<ICreatureState> creatureStates;

        /// <summary>
        /// Initializes a new instance of the <see cref="ArtificialIntelligence"/> class.
        /// </summary>
        /// <param name="creatureStates">
        /// The creature States.
        /// </param>
        public ArtificialIntelligence(List<ICreatureState> creatureStates)
        {
            this.creatureStates = creatureStates;
        }

        /// <summary>
        /// The get next state.
        /// </summary>
        /// <param name="creature">
        /// The creature.
        /// </param>
        /// <returns>
        /// The <see cref="ICreatureState"/>.
        /// </returns>
        public ICreatureState GetNextState(Creature creature)
        {
            var rand = new Random((int)DateTime.Now.Ticks);
            var randomNumber = rand.Next(0, this.creatureStates.Count);
            var state = this.creatureStates[randomNumber];
            return state;
        }
    }
}
